﻿using B.Z.BasicData.Domain.Entity.Authorize;
using B.Z.BasicData.ErrorCode;
using B.Z.BasicData.Infrastructure;
using MediatR;

namespace B.Z.BasicData.API.Read.Application.Menu
{
    public class RoleMenuQueryCommandHandler : IRequestHandler<RoleMenuQueryCommand, APIResult<List<int>>>
    {
        private readonly IBaseRepository<T_RoleMenu> rmRepository;

        public RoleMenuQueryCommandHandler(IBaseRepository<T_RoleMenu> rmRepository)
        {
            this.rmRepository = rmRepository;
        }

        public Task<APIResult<List<int>>> Handle(RoleMenuQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<int>> result = new APIResult<List<int>>();
            result.Code = APIEnum.ok;
            result.Message = "获取成功";
            var list = rmRepository.GetAll().Where(p => p.Rid == request.Rid).Select(x=>x.Mid);
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
